package com.example.springbootkafka.producer;

import com.example.springbootkafka.configration.KafkaFutureCallback;
import com.example.springbootkafka.constant.KafkaConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;


@Component
@Order(1)
public class KafkaProducer1 implements CommandLineRunner {
    private static final Logger log = LoggerFactory.getLogger(KafkaProducer1.class);

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;
    @Autowired
    private KafkaFutureCallback kafkaFutureCallback;

    @Override
    public void run(String... args) throws Exception {
        log.info("这里是CommandLineRunner，order is 1");
        kafkaTemplate.send(KafkaConstant.TOPIC1.getValue(),"这里是CommandLineRunner，order is 1").addCallback(kafkaFutureCallback);
    }
}
